import pandas as pd
import numpy as np

data = pd.read_csv("stock_day.csv").drop(["ma5", "ma10", "ma20", "v_ma5", "v_ma10", "v_ma20"], axis=1)
dummies = pd.get_dummies(pd.qcut(data["high"], q=10))

# 1. conncat()拼接，axis=必须指定，0代表列（即这几个表列相同），1代表行（即这几个表行相同）
conncat = pd.concat([data, dummies], axis=1)
# print(conncat.head(3))
"""
             open   high  ...  (24.636, 26.964]  (26.964, 36.35]
2018-02-27  23.53  25.88  ...              True            False
2018-02-26  22.80  23.78  ...             False            False
2018-02-23  22.88  23.37  ...             False            False
"""

# 2. merge()合并
# pd.merge(left,right,how,on)
# how: 可选参数：left（左连接） right（右连接）
#              outer（外连接） inner（缺省，内连接）
# on：指定共同的键

left = pd.DataFrame({'key1': ['K0', 'K0', 'K1', 'K2'],
                     'key2': ['K0', 'K1', 'K0', 'K1'],
                     'A': ['A0', 'A1', 'A2', 'A3'],
                     'B': ['B0', 'B1', 'B2', 'B3']})

right = pd.DataFrame({'key1': ['K0', 'K1', 'K1', 'K2'],
                      'key2': ['K0', 'K0', 'K0', 'K0'],
                      'C': ['C0', 'C1', 'C2', 'C3'],
                      'D': ['D0', 'D1', 'D2', 'D3']})
merge1 = pd.merge(left, right, on=['key1', 'key2'], how='inner')
print(merge1)
"""
  key1 key2   A   B   C   D
0   K0   K0  A0  B0  C0  D0
1   K1   K0  A2  B2  C1  D1
2   K1   K0  A2  B2  C2  D2
"""